package ru.study.thinkin.chapter14;

import java.util.Random;

public class CoffeeGenerator implements Generator<Coffee>{
	private Random rand = new Random();
	private Class[] types = {Latte.class,Americano.class,Cappuchino.class}; 
	
	private int getRandom() {
		return rand.nextInt(types.length);
	}
	
	@Override
	public Coffee next() {		
		Coffee c = null;
		try {
			 c =(Coffee) types[getRandom()].newInstance();			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return c ;
	}

	public static void main(String[] args) {
		CoffeeGenerator cg = new CoffeeGenerator();
		for (int i =0;i<3;i++) 
			System.out.println(cg.next());
	
	}

}
